<link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
<section id="container" class="">
  <!--main content start-->
  <section id="main-content">
    <section class="wrapper">
      <!--state overview end-->
      <div class="row">
        <div class="col-lg-12">
          <div class="alert alert-block alert-warning fade in">
            <button data-dismiss="alert" class="close close-sm" type="button">
              <i class="icon-remove"></i>
            </button>
            <strong>注意事项：</strong>
            项目经理填写项目进展时，请依据其他重要角色的进展情况给出项目整体进展说明，不能局限于个人单方面的进展；若无进展，请填写无进展及其原因！
            例如（对于销售项目，项目经理要综合销售、技术支持、交付等方面进展给出整体说明）。
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-12">
          <div class="alert alert-block alert-danger fade in">
            <button data-dismiss="alert" class="close close-sm" type="button">
              <i class="icon-remove"></i>
            </button>
            <strong>友情提示：</strong>
            填写进展时，开始时间要以上周周六开始，结束时间填写周五。
          </div>
        </div>
      </div>
      <div class="row">
        <form>
          <div class="col-lg-12">
            <section class="panel">
              <header class="panel-heading">
                项目整体进展信息
              </header>
              <div class="panel-body">
                <div class="panel-body">
                  <div class="form-group customerForm">
                    <label class="col-sm-2 control-label">填写周期*</label>
                    <div class="col-sm-10">
                      <div class="row">
                        <div class="col-lg-6 n-p0">
                          <input id="datetime" disabled name="startTime" type="text" value="{{beginTime}}" class="form-control"
                                 placeholder="开始时间">
                        </div>
                        <div class="col-lg-6 n-p0">
                          <input id="datetime-1" name="endTime" type="text" value="{{endTime}}" style="background-color: #fafafa"
                                 readonly autocomplete="off" class="form-control"
                                 placeholder="结束时间">
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">项目整体进展*</label>
                  <div class="col-sm-10">
                    <textarea class="form-control" id="content" name="content" maxlength="500" placeholder="最多500汉字">{{content}}</textarea>
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">下一步计划*</label>
                  <div class="col-sm-10">
                    <textarea class="form-control" id="nextStep" name="nextStep" maxlength="500" placeholder="最多500汉字">{{nextStep}}</textarea>
                  </div>
                </div>
                <!--<div class="box-hr"><span>本周投标和收入情况</span></div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周投标金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input id="nowBiddingTime" name="nowBiddingTime" type="number" value="{{nowBiddingTime}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周投标说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nowBiddingComments" placeholder="最多120汉字" maxlength="120">{{nowBiddingComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周中标金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input id="nowGetTime" name="nowGetTime" type="number" value="{{nowGetTime}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周中标说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nowGetComments" placeholder="最多120汉字" maxlength="120">{{nowGetComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周流标金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input id="nowLoseTime" name="nowLoseTime" type="number" value="{{nowLoseTime}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周流标说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nowLoseComments" placeholder="最多120汉字" maxlength="120">{{nowLoseComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周非销售金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input id="nowIncome" name="nowIncome" type="number" value="{{nowIncome}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周非销售说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nowIncomeComments" placeholder="最多120汉字" maxlength="120">{{nowIncomeComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">本周客户投诉</label>
                  <div class="col-sm-10">
                    <textarea class="form-control" name="nowCustomerComplain" placeholder="最多120汉字" maxlength="120">{{nowCustomerComplain}}</textarea>
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">本周客户需求</label>
                  <div class="col-sm-10">
                    <textarea class="form-control" name="nowCustomerRequest" placeholder="最多120汉字" maxlength="120">{{nowCustomerRequest}}</textarea>
                  </div>
                </div>
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周决策说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="decisionContent" placeholder="最多500汉字" maxlength="500">{{decisionContent}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">本周决策处理</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="decisionManage" placeholder="最多500汉字" maxlength="500">{{decisionManage}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">风险级别</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<select class="form-control" name="riskLv" id="riskLv" ng-model="riskLv">-->
                      <!--<option value="低">低</option>-->
                      <!--<option value="中">中</option>-->
                      <!--<option value="高">高</option>-->
                    <!--</select>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">风险和问题</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<select class="form-control" disabled>-->
                      <!--<option value="1">开启</option>-->
                    <!--</select>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">风险说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="riskContent" id="riskContent" placeholder="最多500汉字" maxlength="500">{{riskContent}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">预规避和处理措施</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="riskManage" id="riskManage" placeholder="最多500汉字,本周无风险则不用填写" maxlength="500">{{riskManage}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="box-hr"><span>下周预测</span></div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周合同金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input  name="nextContractMoney" type="number" value="{{nextContractMoney}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周合同说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nextContractComments" placeholder="最多120汉字" maxlength="120">{{nextContractComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周开票金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input name="nextInvoice" type="number" value="{{nextInvoice}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周开票说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nextInvoiceComments" placeholder="最多120汉字" maxlength="120">{{nextInvoiceComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周回款金额</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<input name="nextRefoundMoney" type="number" value="{{nextRefoundMoney}}" autocomplete="off" class="form-control">-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周回款说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nextRefoundComments" placeholder="最多120汉字" maxlength="120">{{nextRefoundComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                <!--<div class="form-group customerForm">-->
                  <!--<label class="col-sm-2 control-label">下周投标说明</label>-->
                  <!--<div class="col-sm-10">-->
                    <!--<textarea class="form-control" name="nextBiddingComments" placeholder="最多120汉字" maxlength="120">{{nextBiddingComments}}</textarea>-->
                  <!--</div>-->
                <!--</div>-->
                
              </div>
            </section>
            <section class="panel">
              <div class="panel-body">
                  <p class="default-buttons">
                      <a href="javascript:void(0);" class="button-back btn btn-info" onclick="toBack()">返回</a>
                      <a href="javascript:void(0);" class="button-next  btn btn-success submit">确认提交</a>
                    </p>
              </div>
            </section>
          </div>
        </form>
      </div>
    </section>
  </section>
  <!--main content end-->
</section>
<!-- 当前页面js文件引入 -->
<script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
    $('#datetime-1').datepicker({
        format: 'yyyy-mm-dd'
    }).on('changeDate', function (e) {
        var date = new Date($("#datetime-1").val().replace(/-/, "/").replace("-", "/"));
        //计算相差多少天
        var d = new Date();
        var time = d.getTime() - date.getTime();
        var days = parseInt(time / (1000 * 60 * 60 * 24));
        if (days > 30) {
            layer.msg("结束日期不能超过当前日期30天");
            $("#datetime-1").val("");
            $("#datetime").val("");
            return;
        }

        var weekDay = [7, 1, 2, 3, 4, 5, 6];
        if (weekDay[date.getDay()] != 5) {
            layer.msg("结束日期必须为星期五");
            $("#datetime-1").val("");
            $("#datetime").val("");
            return;
        } else {
            //开始日期为结束日期的前6天
            var now = new Date(date.getTime() - 86400000 * 6);
            var year = now.getFullYear(),
                month = (now.getMonth() + 1).toString(),
                day = now.getDate().toString();
            if (month.length == 1) {
                month = '0' + month;
            }
            if (day.length == 1) {
                day = '0' + day;
            }
            var datetime = (year + '-' + month + '-' + day);
            $("#datetime").val(datetime);
        }
    });

    function toBack() {
        window.history.back();
    }
    function formatTime(param) {
        var date = new Date(param);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
        return content;
    }
  function editjz(CertusFormAjax,$routeParams,$scope) {
      CertusFormAjax.ajax('findReportById',{"id":$routeParams.id},function (response) {
            var data = response.data;
            $scope.content = data.content;
            $scope.nextStep = data.next_step;
            $scope.beginTime = formatTime(data.begin_time);
            $scope.endTime = formatTime(data.end_time);
            // $scope.nowBiddingTime = data.now_bidding_time;
            // $scope.nowBiddingComments = data.now_bidding_comments;
            // $scope.nowGetTime = data.now_get_time;
            // $scope.nowGetComments = data.now_get_comments;
            // $scope.nowLoseTime = data.now_lose_time;
            // $scope.nowLoseComments = data.now_lose_comments;
            // $scope.nowIncome = data.now_income;
            // $scope.nowIncomeComments = data.now_income_comments;
            $scope.nowCustomerComplain = data.now_customer_complain;
            $scope.nowCustomerRequest= data.now_customer_request;
            // $scope.decisionContent = data.decision_content;
            // $scope.decisionManage = data.decision_manage;
            // $scope.riskLv = data.risk_lv;
            // $scope.riskContent = data.risk_content;
            // $scope.riskManage = data.risk_manage;
            // $scope.nextContractMoney = data.next_contract_money;
            // $scope.nextContractComments = data.next_contract_comments;
            // $scope.nextInvoice = data.next_invoice;
            // $scope.nextInvoiceComments = data.next_invoice_comments;
            // $scope.nextRefoundMoney = data.next_refound_money;
            // $scope.nextRefoundComments = data.next_refound_comments;
            // $scope.nextBiddingComments = data.next_bidding_comments;
            $scope.proId = data.pro_id;
            $scope.id = data.id;
      });
      $(".submit").on('click',function () {
          var datetime = $("#datetime").val();
          var endTime = $("#datetime-1").val();
          if (datetime==""){
              layer.msg("结束日期不能为空",{time:1000});
              return;
          }
          var startTime = new Date(datetime.replace("/", "-").replace("/", "-"));
          if (datetime!=""){
              var endTimes = new Date(endTime.replace("/", "-").replace("/", "-"));
              if (startTime>endTimes){
                  layer.msg("开始日期不能大于结束日期",{time:1000});
                  return;
              }
          }else{
              layer.msg("开始日期不能为空",{time:1000});
              return;
          }
          var content = $("#content").val();
          if (content==""){
              layer.msg("整体进展不能为空",{time:1000});
              return;
          }
          if (content.length>500){
              layer.msg("整体进展不能超过500字",{time:1000});
              return;
          }
          var nextStep = $("#nextStep").val();
          if (nextStep==""){
              layer.msg("下一步计划不能为空",{time:1000});
              return;
          }
          if (nextStep.length>500){
              layer.msg("整体进展不能超过500字",{time:1000});
              return;
          }
          var arr = $("form").serializeArray();
          var data = {};
          for (var i = 0; i < arr.length; i++) {
              data[arr[i].name] = arr[i].value;
          };
          data.id = $routeParams.id;
          data.startTime = datetime;
          CertusFormAjax.ajax("editReport2",{"param":JSON.stringify(data)},function () {
              layer.msg("修改成功",{"time":1000});
              window.history.back();
          })
          var nextStep = $("#nextStep").val();
      })
  }
    //n为你要传入的参数，当前为0，前一天为-1，后一天为1
    function getBeforeDate(n) {
        var date = new Date();
        var year, month, day;
        date.setDate(date.getDate() + n);
        year = date.getFullYear();
        month = date.getMonth() + 1;
        day = date.getDate();
        s = year + '-' + (month < 10 ? ('0' + month) : month) + '-' + (day < 10 ? ('0' + day) : day);
        return s;
    }
</script>
